#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second

typedef long long ll;
typedef pair<int, int> pii;

const int N = 2e5 + 5;
const int M = 1e9 + 7;

int n, m;
pii s[N];

int stk[N], t = 0;

bool cmp(pii a, pii b) {
    return a.x != b.x ? a.x<b.x : a.y>b.y;
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        s[i] = { u, v };
    }

    sort(s, s + m, cmp);

    stk[++t] = s[0].y;
    for (int i = 1; i < m; i++) {
        if (stk[t] < s[i].y)
            stk[++t] = s[i].y;
        else {
            auto p = lower_bound(stk, stk + t, s[i].y);
            *p = s[i].y;
        }
    }
    cout << t << endl;
    return 0;
}